// import axios from 'axios'

const getRoleList = async (params) => {
    return await new Promise((resolve, reject) => {
        axios.get("/index/role/getRoleList", params).then(res => {
            resolve(res.data.data);
        }).catch(err => {
            reject(err);
        })
    })
}

// http://localetest.vkforest.com/auth-reform/public/index.php/index/role/newRoleList 
// pageNumber， pageSize， name

const getNewRoleList = async (params) => {
  console.log(params)
    if (params) {
        params = Object.assign({
            pageSize: 10,
            pageNumber: 1
        }, params);

        return await new Promise((resolve, reject) => {
            axios.get("/index/role/newRoleList", {
                params
            }).then(res => {
                resolve(res.data.data);
            }).catch(err => {
                reject(err);
            });
        });
    } else {
      return await new Promise((resolve, reject) => {
        axios.get("/index/role/allRole").then(res => {
            resolve(res.data.data);
        }).catch(err => {
            reject(err);
        });
    });
    }

}

const getManagerRole = async () => {
    return await new Promise((resolve, reject) => {
        axios.get("/index/role/getManagerRole").then(res => {
            resolve(res.data.data);
        }).catch(err => {
            reject(err);
        })
    })
}

const getNoInManagerRoleList = async () => {
    return await new Promise((resolve, reject) => {
        axios.get("/index/role/workerNoInManagerRoleList").then(res => {
            resolve(res.data.data);
        }).catch(err => {
            reject(err);
        })
    })
}

const addManagerUser = async (params) => {
    return await new Promise((resolve, reject) => {
        axios.post('/index/role/addManagerUser', params).then(res => {
            resolve(res);
        }).catch(err => {
            reject(err);
        })
    })
}

// http://localetest.vkforest.com/auth-reform/public/index.php/index/role/newRoleUserList?roleId=

const getRoleDetail = async (id) => {
    return await new Promise((resolve, reject) => {
        axios.get("/index/role/newRoleUserList?roleId=" + id).then(res => {
            resolve(res.data.data);
        }).catch(err => {
            reject(err);
        });
    });
}

const createRole = async (params) => {
    return await new Promise((resolve, reject) => {
        axios.post("/index/role/createRole", params).then(res => {
            resolve(res);
        }).catch(err => {
            reject(err);
        })
    })
}

const editRole = async (params) => {
    return await new Promise((resolve, reject) => {
        axios.post("/index/role/editRole", params).then(res => {
            resolve(res);
        }).catch(err => {
            reject(err);
        })
    })
}

const getWorkerNoInRoleList = async (params) => {
    params.pageNumber = params.pageNumber || 1;
    params.pageSize = 10;
    return await new Promise((resolve, reject) => {
        axios.get("/index/role/workerNoInRoleList", {
            params
        }).then(res => {
            resolve(res.data.data);
        }).catch(err => {
            reject(err);
        })
    })
}

const removeUserOutRole = async (params) => {
    return await new Promise((resolve, reject) => {
        axios.post("/index/role/removeUserRole", params).then(res => {
            resolve(res);
        }).catch(err => {
            reject(err);
        })
    })
}

const delRole = async (params) => {
    return await new Promise((resolve, reject) => {
        axios.post("/index/role/delRole", params).then(res => {
            resolve(res);
        }).catch(err => {
            reject(err);
        })
    })
}

const addUserIntoRole = async (params) => {
    return await new Promise((resolve, reject) => {
        axios.post('/index/role/addUserIntoRole', params).then(res => {
            resolve(res)
        }).catch(err => {
            reject(err)
        })
    })
}

const getAllUser = async () => {
    return await new Promise((resolve, reject) => {
        axios.get('/index/manager/getAllUser', {}).then(res => {
            resolve(res.data.data)
        }).catch(err => {
            reject(err)
        })
    })
}

const getCode = async () => {
    return await new Promise((resolve, reject) => {
        axios.get('/index/manager/sendSms', {}).then(res => {
            resolve(res.data.data)
        }).catch(err => {
            reject(err)
        })
    })
}

const attornSuperManager = async (params) => {
    return await new Promise((resolve, reject) => {
        axios.post('/index/manager/attornSuperManager', params).then(res => {
            resolve(res)
        }).catch(err => {
            reject(err)
        })
    })
}

export default {
    getRoleList,
    getNewRoleList,
    getRoleDetail,
    getManagerRole,
    addManagerUser,
    createRole,
    delRole,
    editRole,
    getWorkerNoInRoleList,
    getNoInManagerRoleList,
    removeUserOutRole,
    addUserIntoRole,
    getAllUser,
    getCode,
    attornSuperManager
}
